<template>
  <div>
    <Portlet :title="innerTitle">
      <el-button v-if="isEdit" slot="tools" @click.prevent="toEditing" type="primary">修改</el-button>
      <el-form label-position="left" label-width="120px">
        <el-row class="row">
          <el-col :lg="8" :md="12" :xl="6">
            <el-form-item label="登陆账号:">
              <span>{{ userInfo.loginName }}</span>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :md="12" :xl="6">
            <el-form-item label="角色名称:">
              <span>{{ roleNames }}</span>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :md="12" :xl="6">
            <el-form-item label="状态:">
              <span>{{ userInfo.state == 1 ? '启用' : '停用'}}</span>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :md="12" :xl="6">
            <el-form-item label="创建人:">
              <span>{{userInfo.foundUserName}}</span>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :md="12" :xl="6">
            <el-form-item label="创建时间:">
              <span>{{userInfo.foundtime | unixTimestampFilter}}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="clearfix"></div>
    </Portlet>
  </div>
</template>
<script>
// import UserInfo from './UserInfo'
import {dotData} from '@/utils'
export default {
  name: 'fhbAccountShow',
  props: {
    projectType: {
      type: String,
      default: process.env.projectType
    },
    title: {
      type: String,
      default: '基本信息'
    },
    changePassword: {
      type: Boolean,
      default: false
    }
  },
  components: {
    // UserInfo
  },
  data() {
    return {
      routeName: this.$route.name,
      id: this.$route.params.id,
      isChangePassword: false,
      data: {}
    }
  },
  created() {
    this.getData()
  },
  computed: {
    isEdit() {
      return !!this.id
    },
    innerTitle() {
      return this.title
    },
    userId() {
      return this.userInfo.id
    },
    userInfo() {
      return dotData(this.data, 'orgUser') || {}
    },
    roleNames() {
      const roleExtBeans = dotData(this.data, 'roleExtBeans') || []
      if (Array.isArray(roleExtBeans)) {
        return roleExtBeans.map(v => v.name).join(',')
      }
      return ''
    }
  },
  methods: {
    getData() {
      // 用列表带进来的userId请求的详情：接口为scm的详情接口，修改了前缀
      // /ms-user-storage/org-user/findByOrgUser
      // 请求 详情页面的数据
      this.$ajax.get('/ms-common-user/user/getUserAllDetails', {userId: this.id, projectType: this.projectType}).then(response => {
        if (!response.data) {
          return
        }
        // this.userInfo = dotData(response, 'data.orgUser')
        this.data = response.data || {}
      })
    },
    toEditing() {
      this.$router.push({path: '/ss-fhb/account/edit/' + this.userId})
    },
    refresh(val) {
      this.getData()
    }
  }
}
</script>
